/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import com.jnetx.javax.sip.util.Parameterized;

import javax.sip.header.Header;
import javax.sip.header.Parameters;
import java.text.ParseException;
import java.util.Iterator;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public abstract class ParameterizedHeaderBase extends HeaderBase implements Parameters {
    private final Parameterized<Header> parameterized = new Parameterized<Header>(this);

    protected ParameterizedHeaderBase(String name) {
        super(name);
    }

    protected ParameterizedHeaderBase(String name, byte[] data, int start, int end) {
        super(name, data, start, end);
    }

    public String getParameter(String name) {
        parse();
        return parameterized.getParameter(name);
    }

    public void setParameter(String name, String value) throws ParseException {
        parse();
        parameterized.setParameter(name, value);
        invalidateHeaderData();
    }

    public Iterator getParameterNames() {
        parse();
        return parameterized.getParameterNames();
    }

    public void removeParameter(String name) {
        parse();
        parameterized.removeParameter(name);
        invalidateHeaderData();
    }

    protected void cloneParameters(ParameterizedHeaderBase source) {
        parameterized.putParameters(source.parameterized.getParameters());
    }

    @Override
    protected StringBuilder getParametersAsString(StringBuilder sb) {
        return parameterized.getParametersAsString(sb);
    }
}
/*
 * $Log$
 */